<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>websocket测试</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <style type="text/css">
        h3, h4 {
            text-align: center;
        }
    </style>
</head>
<body>

<h3>WebSocket测试，客户端接收到的消息如下：</h3>

<textarea cols="150" id="messageId" readonly="readonly" rows="30">

</textarea>


<script crossorigin="anonymous" integrity="sha384-HHKD5G6fqvxz/wBz7BFYeOPzBKELGIZv5l5HAECcXD3zdAS6n8OppmPH9ZxGXY0G"
        src="https://lib.baomitu.com/socket.io/2.3.0/socket.io.js"></script>

<script>

    $(function () {
        //  io.connect('http://localhost:8899/push', {
        //     'path': '/push',
        //     'force new connection': true,
        //     'reconnection': true,
        //     'reconnectionDelay': 2000,                  // starts with 2 secs delay, then 4, 6, 8, until 60 where it stays forever until it reconnects
        //     'reconnectionDelayMax': 5000,               // 1 minute maximum delay between connections
        //     'reconnectionAttempts': 10,         // to prevent dead clients, having the user to having to manually reconnect after a server restart.
        //     'timeout': 10000,                           // before connect_error and connect_timeout are emitted.
        //     'transports': ['websocket', 'polling'],
        //     'query': {
        //         'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX25hbWUiOiJ0b20iLCJqdGkiOiIxIiwiaWF0IjoxNjA2Mjk3NDAyLCJleHAiOjQwOTkyODMwMDJ9.B9-ctSkAWQIry4ZcrxM_zjB_Fuf5TJ_EQOQqu0lDAXg',
        //
        //     }
        // }).on("message", function (data) {
        //     console.log(data);
        //     // $('#x').text(data.x);
        //     // $('#y').text(data.y);
        //
        // });


        var socket = io('http://localhost:8899', {
                'path': '/push',
            'force new connection': true,
            'reconnection': true,
            'reconnectionDelay': 2000,                  // starts with 2 secs delay, then 4, 6, 8, until 60 where it stays forever until it reconnects
            'reconnectionDelayMax': 5000,               // 1 minute maximum delay between connections
            'reconnectionAttempts': 10,         // to prevent dead clients, having the user to having to manually reconnect after a server restart.
            'timeout': 10000,                           // before connect_error and connect_timeout are emitted.
            'transports': ['websocket', 'polling'],
                'query': {
                    'Authorization': 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxMDAwMzAwMTgsInVzZXJfbmFtZSI6InRvbSIsImp0aSI6IjEiLCJpYXQiOjE2MDYzNjAzNzMsImV4cCI6NDA5OTM0NTk3M30.KMnZ8cKP82c94AwjxhDTyAT0P0J-OLpIw2snvUaPXTw',

                }
        });//用于连接后端的服务


        socket.on("message", function (data) {
            console.log(data);

            $('#messageId').val(data.data.content+"已经上线")
        });


    })
</script>


</body>
</html>